/*
 * Copyright (c) 2023, mdf Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2023-10-18     MacRsh       First version
 */

#ifndef MDF_API_H
#define MDF_API_H

#include "inc/mdf_def.h"
#include "inc/mdf_service.h"

void mdf_interrupt_disable(void);
void mdf_interrupt_enable(void);

void *mdf_malloc(size_t size);
void mdf_free(void *memory);

void mdf_ringbuf_init(struct mdf_ringbuf *ringbuf, void *pool, size_t size);
int mdf_ringbuf_allocate_buffer(struct mdf_ringbuf *ringbuf, size_t size);
void mdf_ringbuf_reset(struct mdf_ringbuf *ringbuf);
size_t mdf_ringbuf_get_data_size(struct mdf_ringbuf *ringbuf);
size_t mdf_ringbuf_get_space_size(struct mdf_ringbuf *ringbuf);
size_t mdf_ringbuf_get_buffer_size(struct mdf_ringbuf *ringbuf);
size_t mdf_ringbuf_pop(struct mdf_ringbuf *ringbuf, uint8_t *data);
size_t mdf_ringbuf_read(struct mdf_ringbuf *ringbuf, void *buffer, size_t size);
size_t mdf_ringbuf_push(struct mdf_ringbuf *ringbuf, uint8_t data);
size_t mdf_ringbuf_push_force(struct mdf_ringbuf *ringbuf, uint8_t data);
size_t mdf_ringbuf_write(struct mdf_ringbuf *ringbuf, const void *buffer, size_t size);
size_t mdf_ringbuf_write_force(struct mdf_ringbuf *ringbuf, const void *buffer, size_t size);


int mdf_dev_register(struct mdf_dev *dev,
                     const char *name,
                     uint32_t type,
                     uint32_t sflags,
                     struct mdf_dev_ops *ops,
                     struct mdf_drv *drv);
int mdf_dev_open(const char *name, uint32_t oflags);
int mdf_dev_close(int desc);
ssize_t mdf_dev_read(int desc, void *buf, size_t size);
ssize_t mdf_dev_write(int desc, const void *buf, size_t size);
int mdf_dev_ioctl(int desc, int cmd, void *args);
void mdf_dev_isr(struct mdf_dev *dev, uint32_t event);

#endif /* MDF_API_H */
